import { replaceTpl } from '../../libs/utils';
import tpl0 from './tpl/tpl0.tpl';
import tpl1 from './tpl/tpl1.tpl';
import tpl2 from './tpl/tpl2.tpl';
import tpl3 from './tpl/tpl3.tpl';
import wrapperTpl from './tpl/wrapper.tpl';
import './index.scss'
export default {
    name: 'NewsList',
    //外层容器的top距离在首页新闻列表也和收藏新闻列表页不同
    wrapperTpl(top) {
        return replaceTpl(wrapperTpl, {
            top
        })
    },
    //新闻列表页图片数量不同需选用不同的模版适应
    tpl(options) {
        const { data, pageNum } = options;
        let list = '',
            tpl = '';
        //遍历每一条新闻数据选出对应模版去替换变量加到list中
        data.map((item, index) => {
            if (!item.thumbnail_pic_s) { tpl = tpl0; }
            else if (item.thumbnail_pic_s && !item.thumbnail_pic_s02) { tpl = tpl1; }
            else if (item.thumbnail_pic_s02 && !item.thumbnail_pic_s03) { tpl = tpl2; }
            else if (item.thumbnail_pic_s03) { tpl = tpl3 }
            list += replaceTpl(tpl, {
                pageNum,
                index,
                uniquekey: item.uniquekey,
                url: item.url,
                author: item.author_name,
                date: item.date,
                thumbnail_pic_s: item.thumbnail_pic_s,
                thumbnail_pic_s02: item.thumbnail_pic_s02,
                thumbnail_pic_s03: item.thumbnail_pic_s03,
                title: item.title,
                category: item.category
            });
        });
        return list;
    }
}